<template>
    <div class="forum-list-wrap">
        <div class="banner">
            <el-carousel height="5.5rem">
                <el-carousel-item v-for="(item,index) in bannerList" :key="index">
                    <div class="banner-img" @click="clickBannerFun(item)">
                        <img :src="item.image" alt="" />
                    </div>
                </el-carousel-item>
            </el-carousel>
        </div>

        <div class="type">
            <div class="type-item" @click="selectTabFun(item,index)" :class="{'type-item-active':tabCurrent == index}" v-for="(item,index) in tabList" :key="index">{{ item.title }}</div>
        </div>

        <div class="list" v-for="(val,key) in list" :key="key">
            <div class="list-title">{{ val.title }}</div>
            <div class="data">
                <div class="data-item" v-for="(item, index) in val.list" :key="index">
                    <StudyItem3  :item="item"></StudyItem3>
                </div>
            </div>
        </div>


    </div>
</template>

<script>
import StudyItem3 from "./pageComponents/study-item3.vue";

import {getProductType} from "@/api/study";
import {getBanner} from "@/api/common";
export default {
    components: {
        StudyItem3,
    },
    data() {
        return {
            bannerList: [],
            list:[],
            // 新增
            tabList: [
                { title: "视频", type: "1" },
                { title: "文档", type: "2" },
            ],
            tabCurrent: 0,
        };
    },
    mounted() {
        this.getListFun();
        this.getBannerFun()
    },
    methods: {
        getBannerFun() {
            getBanner().then(res => {
                this.bannerList = res.data
            })
        },
        clickBannerFun(item){
            if(item.url){
                window.location.href = item.url
            }
        },
        selectTabFun(item, index) {
            if(this.tabCurrent == index) return;
            this.tabCurrent = index;
            this.getListFun()
        },
        getListFun(){
            let item = this.tabList[this.tabCurrent]
            getProductType({type_id:this.$route.params.id,type:item.type}).then(res=>{
                if(res.code ==200){
                    this.list = res.data
                }
            })
        }
    },
};
</script>

<style lang="less" scoped>
.forum-list-wrap {
    .banner {
        width: 100%;
        height: 5.5rem;
        .banner-img {
            display: flex;
            justify-content: center;
            align-items: center;
            width: 100%;
            height: 100%;
            img {
                width: 100%;
                height: 100%;
            }
        }
    }
    
    .type{
        display: flex;
        align-items: center;
        padding-top: 0.375rem;
        .type-item{
            display: flex;
            justify-content: center;
            align-items: center;
            width: 1.5rem;
            height: 0.5rem;
            background: #EEF6FE;
            font-size: 0.25rem;
            color: #000;
            cursor: pointer;
            margin-right: 0.375rem;
        }
        .type-item-active{
            background: #4F8AF8;
            color: #fff;
        }
    }

    .list {
        padding-top: 0.5rem;
    }
    .list-title{
        display: flex;
        align-items: center;
        box-sizing: border-box;
        padding-left: 0.5rem;
        font-size: 0.3rem;
        color: #000;
        height: 1rem;
        background: rgba(79,138,248,0.1);
        margin-bottom: 0.5rem;
    }
    .data{
        display: flex;
        flex-wrap: wrap;
        .data-item{
            width: 4.1875rem;
            margin-right: 0.25rem;
            margin-bottom: 0.375rem;
            &:nth-child(4n){
                margin-right: 0;
            }
        }
    }
    .pagination {
        display: flex;
        justify-content: center;
        padding: 0.375rem 0 1rem;
    }
}
</style>